import Vue from 'vue'
import FastClick from 'fastclick'
import VueBus from 'vue-bus'
import { WechatPlugin, AjaxPlugin, AlertPlugin, ToastPlugin, ConfirmPlugin, DatetimePlugin, BusPlugin, DevicePlugin } from 'vux'
import store from 'store'
import router from 'src/router'
import vuexI18n from 'vuex-i18n'

import * as constants from 'src/AppConstants'
import common_mixins from 'mixins/common_mixins'

require('plugins/http')
require('libs/flexible')
require('libs/rem')
require('animate.css')

require('es6-promise').polyfill()

import App from './App'

import objectAssign from 'object-assign'

// i18n配置
Vue.use(vuexI18n.plugin, store)

const vuxLocales = require('json-loader!yaml-loader!./locales/all.yml')
const componentsLocales = require('json-loader!yaml-loader!./locales/components.yml')

const finalLocales = {
    'en': objectAssign(vuxLocales['en'], componentsLocales['en']),
    'zh-CN': objectAssign(vuxLocales['zh-CN'], componentsLocales['zh-CN'])
}

for (let i in finalLocales) {
    Vue.i18n.add(i, finalLocales[i])
}
Vue.i18n.set('zh-CN')

Vue.use(VueBus) // 全局事件
Vue.use(WechatPlugin) // 微信插件
Vue.use(AjaxPlugin) // axios(ajax请求)
Vue.use(AlertPlugin)
Vue.use(ToastPlugin)
Vue.use(ConfirmPlugin)
Vue.use(DatetimePlugin)
Vue.use(BusPlugin)
Vue.use(DevicePlugin)

FastClick.attach(document.body)

// 调试参数配置
Vue.config.productionTip = false
Vue.config.devtools = process.env.NODE_ENV !== constants.ENV_PRODUCTION

// bug报告SDK配置
if (process.env.NODE_ENV !== constants.ENV_PRODUCTION) {
    // web控制台
    require('vconsole')
}

// 全局混合
Vue.mixin(common_mixins)

new Vue({
    router,
    store,
    render: h => h(App)
}).$mount('#app-box')